package com.cxmx.escort.config.sdk;

import com.huawei.iotplatform.client.NorthApiClient;
import com.huawei.iotplatform.client.NorthApiException;
import com.huawei.iotplatform.client.dto.ClientInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class NBIoTService {

    @Value("${nb.oceanconnect.appId}")
    public String appId;

    @Value("${nb.oceanconnect.secret}")
    public String secret;

    @Value("${nb.oceanconnect.platformHost}")
    public String platformHost;

    @Value("${nb.oceanconnect.platformPort}")
    public String platformPort;

    NorthApiClient northApiClient = null;

    @PostConstruct
    private void postConstruct() throws NorthApiException{
        northApiClient = new NorthApiClient();
        ClientInfo clientInfo = new ClientInfo();
        clientInfo.setAppId(appId);
        clientInfo.setPlatformIp(platformHost);
        clientInfo.setPlatformPort(platformPort);
        clientInfo.setSecret(secret);
        northApiClient.setClientInfo(clientInfo);
        northApiClient.initSSLConfig();
    }


    public NorthApiClient getNorthApiClient() throws NorthApiException {

        return northApiClient;
    }

    /*    Setters     */

    public String getAppId() {
        return appId;
    }

    public String getSecret() {
        return secret;
    }
}
